package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Publish;
import com.tanhua.server.service.MovementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/movements")
public class MovementsController {
    @Autowired
    private MovementsService movementsService;

    /**
     * 圈子-推荐动态
     * GET /movements/recommend
     */
    @GetMapping("/recommend")
    public ResponseEntity recommend(int page, int pagesize) {
        return movementsService.recommend(page, pagesize);
    }

    /**
     * 圈子-动态-发布
     * POST /movements
     */
    @PostMapping
    public ResponseEntity movements(Publish publish, String location, MultipartFile[] imageContent) throws IOException {
        publish.setLocationName(location);
        return movementsService.movements(publish, imageContent);
    }

    /**
     * 圈子-好友动态
     * GET /movements
     */
    @GetMapping
    public ResponseEntity friendPublishList(int page, int pagesize) {
        return movementsService.friendPublishList(page, pagesize);
    }

    /**
     * 圈子-用户动态(我的相册)
     * GET /movements/all
     */
    @GetMapping("/all")
    public ResponseEntity all(@RequestParam(defaultValue = "1") int page,
                              @RequestParam(defaultValue = "10") int pagesize,
                              @RequestParam(required = false) Long userId) {
        return movementsService.all(page, pagesize, userId);
    }

    /**
     * 圈子-动态-点赞
     * GET /movements/:id/like
     */
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String publishId) {
        return movementsService.like(publishId);
    }

    /**
     * 圈子-动态-取消点赞
     * GET /movements/:id/dislike
     */
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String publishId) {
        return movementsService.dislike(publishId);
    }

    /**
     * 圈子-动态-喜欢
     * GET /movements/:id/love
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String publishId) {
        return movementsService.love(publishId);
    }

    /**
     * 圈子-动态-喜欢
     * GET /movements/:id/unlove
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String publishId) {
        return movementsService.unlove(publishId);
    }

    /**
     * 动态-查询单条动态（跳转到评论界面时，需要显示动态内容）
     * GET  /movements/:id
     */
    @GetMapping("/{publishId}")
    public ResponseEntity findOnePublish(@PathVariable("publishId") String publishId) {
        return movementsService.findOnePublish(publishId);
    }

    /**
     * 圈子-谁看过我
     * GET /movements/visitors
     */
    @GetMapping("/visitors")
    public ResponseEntity visitors() {
        return movementsService.findVisitorList();
    }

}
